package server;

import game.resources.Profile;

import java.util.ArrayList;
import java.util.List;


public class Room {

    private int counter = 0;
    private int roomSize;   
    private List<Profile> roomClients;
    private String roomName;
    
    public Room(Profile profile, int roomSize, String roomName) {
        this.roomSize = roomSize;
        this.setRoomName(roomName);
        roomClients = new ArrayList<Profile>();
        addToRoom(profile);     
    } 
    
    public int getRoomSize() {
    	return roomSize;
    }
    
    public int getNumOfPlayersInRoom() {
    	return counter;
    }
    
    public boolean addToRoom(Profile profile) {
        if (!isFull()) {
            roomClients.add(profile);
            counter++;
            if (!isFull())
            {
            	// TODO stuff to notify other users
            }
            else
            {
                // TODO stuff to start new game
            }
            return true;
        } else {
            return false;
        }
    }
    
    public boolean isFull() {
        return (counter == roomSize);
    }
    
    public List<Profile> getClients() {
        return roomClients;
    }

    public Profile getClientByID(long clientID) {
        for (Profile profile : roomClients) {
            if (profile.getUserID() == clientID) {
                return profile;
            }
        }
        return null;
    }
    
    public void setRoomName(String roomName) {
        this.roomName = roomName;
    }

    public String getRoomName() {
        return roomName;
    }
    
   
}
